<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>运营商更新</span>
      <el-button style="float: right; padding: 3px 0" type="text" @click="returns">返回</el-button>
      <el-button style="float: right; padding: 3px 0" type="text" @click="updAdmin">提交</el-button>
    </div>
    <el-row>
      <el-form ref="form" :model="admin" label-width="80px">
        <el-form-item label="账号">
          <el-input v-model="admin.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="admin.password"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="admin.email"></el-input>
        </el-form-item>
        <el-form-item label="创建日期">
          <el-col :span="11">
            <el-date-picker type="date" placeholder="选择日期" v-model="admin.created" style="width: 100%;"></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="名字">
          <el-input v-model="admin.name"></el-input>
        </el-form-item>
      </el-form>
    </el-row>
  </el-card>
</template>

<script>
    export default {
        name: "UpdateAdmin",
      data(){
          return{
            admin:{},
          }
      },methods:{
        returns(){
          this.$router.push("AdminList")
        },
        updAdmin(){
          this.axios.put("http://localhost:8001/admin/update",this.admin).then(res=>{
            if(res.data.flag){
              alert("修改成功");
              this.$router.push("AdminList")
            }else{
              alert("修改失败")
            }
          })
        },
          findBy(id){
            this.axios.get("http://localhost:8001/admin/find/"+id).then(res=>{
              this.admin=res.data.data;
            })
          }
      },mounted(){
          var loc=location.href;
          var id=loc.substring(loc.indexOf("=")+1)
        console.log(id)
        this.findBy(id);
      }
    }
</script>

<style scoped>

</style>
